package com.zcf.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zcf.common.json.Body;
import com.zcf.common.result.ResultVo;
import com.zcf.mapper.MessagesMapper;
import com.zcf.pojo.Messages;
import com.zcf.service.MessagesService;
import com.zcf.utils.Hutool;
import com.zcf.vo.in.PageVo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 搜索历史记录表 前端控制器
 * </p>
 *
 * @author loupeng
 * @since 2018-12-20
 */
@Controller
@RequestMapping("/messages")
@CrossOrigin
public class MessagesController {

	@Autowired
	MessagesMapper messagesMapper;
	@Autowired
	MessagesService messagesService;

	/**
	 * 添加搜索历史
	 */
	@PostMapping("insert")
	@ResponseBody
	public Body insert(Messages messages) {
		messages.setMessageId(Hutool.getId());
		messages.setAddtime(Hutool.parseDateToString());
		Boolean flag = messages.insert();
		if (flag) {
			return Body.newInstance(messages);
		}
		return Body.newInstance("添加失败");
	}

	/**
	 * 查询历史记录
	 */
	@PostMapping("queryList")
	@ResponseBody
	public Body queryList(String userId) {
		if (messagesMapper.queeryList(userId) == null) {
			return Body.newInstance("查询失败");
		}
		return Body.newInstance(messagesMapper.queeryList(userId));
	}

}
